# -*- coding: UTF-8 -*-
import requests
import cookielib
import time

class FollowUser():
    
    def __init__(self):
        self.session = requests.session()
        self.session.cookies = cookielib.LWPCookieJar()
        self.session.cookies.load("../cookies/logincookies", ignore_discard=True, ignore_expires=True)
        self.url = "http://s.weibo.com/ajax/user/follow?__rnd="
        self.headers = {}
        self.headers['User-Agent'] = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36"
        self.headers['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
        self.headers['Accept-Encoding'] = 'gzip, deflate, sdch'
        self.headers['Accept-Language'] = 'zh-CN,zh;q=0.8'
        self.headers['Origin'] = "http://s.weibo.com"
        self.headers['refer'] = "http://weibo.com/"
        self.headers['Content-Type'] = 'application/x-www-form-urlencoded'
        
    def follow(self, uid):
        posturl = self.url + str(int(time.time()))
        postData = {
                "uid" : uid,
                'type' : 'followed',
                'wforce' : '0',
                '_t' : '0'
             }
        r = self.session.post(posturl, data=postData, headers = self.headers)
        if r.status_code == 200 :
            print "success"
            pass
        
    def __del__(self):
        self.session.close() 
         

        
        
